from sqlalchemy import Column, BigInteger, String, SmallInteger, DateTime, Index
from app.config.database import Base
from datetime import datetime
from pydantic import BaseModel, ConfigDict
from typing import Optional

class Role(Base):
    __tablename__ = "sys_role"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="角色ID")
    role_code = Column(String(50), nullable=False, comment="角色编码")
    role_name = Column(String(50), nullable=False, comment="角色名称")
    role_desc = Column(String(200), comment="角色描述")
    status = Column(SmallInteger, nullable=False, default=1, comment="状态：0-禁用 1-启用")
    create_time = Column(DateTime, default=datetime.utcnow, nullable=False, comment="创建时间")
    update_time = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False, comment="更新时间")

class RoleInDB(BaseModel):
    id: int
    role_code: str
    role_name: str
    role_desc: Optional[str] = None
    status: int = 1
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None

    model_config = ConfigDict(from_attributes=True)